/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package mjma_attendance_system;


import javax.swing.*;
import java.awt.event.*;
/**
 *
 * @author JM
 */
public class MJMA_Attendance_System 
{
    private JFrame Header = new JFrame("Miriam Junior Marketing Association - ASYS 1.0");
    private JMenuBar MenuHeader = new JMenuBar();
    
    private JMenu CloseOption = new JMenu("Close MJMA-ASYS 1.0");
    private JMenuItem SignalClose = new JMenuItem("Exit MJMA-ASYS 1.0");
    
    private JLabel Welcome = new JLabel("Welcome to MJMA Attendance System 1.0! Please Log-in.");
   
    private JLabel UName = new JLabel("Username:");
    private JLabel UPass = new JLabel("Password:");
    
    private JLabel UPort = new JLabel("DB Port Number:");
    private JLabel USource = new JLabel("DB Source:");
    
    private JButton ULaunch = new JButton("Launch Attendance System");
    
    private JPanel SystemPanel = new JPanel();

    private JTextField UNameField = new JTextField(30);
    private JPasswordField UPassField = new JPasswordField(30);
    private JTextField UPortField = new JTextField(30);
    private JTextField USourceField = new JTextField(30);
    
    //Enable only for the use of Ms. Anna Patricia Despojo.
    //ImageIcon picturetoInsert = new ImageIcon("C:/Users/msi/Pictures/MJMA Logo.jpg");
    ImageIcon picturetoInsert = new ImageIcon("C:/Users/JM/Documents/NetBeansProjects/MJMA_Attendance_System/src/MJMA Logo.jpg");
    private JLabel ImageCatch = new JLabel("",picturetoInsert,JLabel.CENTER);
    /**
     *
     */
    public MJMA_Attendance_System()
    {
       Header.setJMenuBar(MenuHeader);
       CloseOption.add(SignalClose);
       MenuHeader.add(CloseOption);
       
       SystemPanel.setLayout(null);
       SystemPanel.add(Welcome);
       SystemPanel.add(UName);
       SystemPanel.add(UPass);
       SystemPanel.add(UPort);
       SystemPanel.add(USource);
       SystemPanel.add(ULaunch);
       SystemPanel.add(ImageCatch);       
       SystemPanel.add(UNameField);
       SystemPanel.add(UPassField);
       SystemPanel.add(USourceField);
       SystemPanel.add(UPortField);
       
       
       ULaunch.addActionListener(new Execute());
       
    }
    
    public void MJMAAsysEntryPoint()
    {   
        ImageCatch.setBounds(5,20,647,343);
    
          Welcome.setBounds(660,-60,350,350);
          UName.setBounds(710,-30,250,350);
          UPass.setBounds(710,0,250,350);
          UPort.setBounds(710,30,250,350);
          USource.setBounds(710,60,250,350);
          ULaunch.setBounds(720,250,200,30);
        
          UNameField.setBounds(785,130,140,25);
          UPassField.setBounds(785,160,140,25);
          UPortField.setBounds(810,190,115,25);
          USourceField.setBounds(785,220,140,25);
        
        Header.add(SystemPanel);
        Header.setResizable(false);
        Header.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        Header.pack();
        Header.setSize(1000,450);
        Header.setLocationRelativeTo(null);
        Header.setVisible(true);
        
    }
    
    public class Execute implements ActionListener{
        @Override
        
        public void actionPerformed(ActionEvent e)
        {
            boolean Authenticated = false;
            
            String FetchUsername=UNameField.getText();
            String FetchPassword;
            FetchPassword = new String(UPassField.getPassword());
            String FetchPort;
            FetchPort = UPortField.getText();
            String FetchDBSource=USourceField.getText();
          
            
            CredentialController Verify = new CredentialController();
           Authenticated =  Verify.VerifyUserCredentials(FetchUsername, FetchPassword, FetchPort, FetchDBSource); 
            
           
           if(Authenticated == true)
           {
           JOptionPane.showMessageDialog(null, "You are authenticated!");    
           }
           
        }
    }
    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) 
    {
        // TODO code application logic here
        MJMA_Attendance_System ActivateSystem = new MJMA_Attendance_System();
        ActivateSystem.MJMAAsysEntryPoint();
    }
}
